<template>
  <el-dialog
    append-to-body
    :close-on-click-modal="false"
    :visible.sync="dialogFormVisible"
    :before-close="close"
    :title="title"
    width="600px"
    :top="'10vh'"
  >
    <el-form ref="form" :model="form" size="small" label-width="120px" style="min-height: 300px">
      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item
            label="关联问题项"
            prop="glwt"
            :rules="{ required: true, message: '关联问题项不能为空', trigger: 'blur' }"
          >
            <custom-pager-select :id="form.id" v-model="form.glwt" :length="4" placeholder="请选择关联项" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="close">取消</el-button>
      <el-button :loading="loading" type="primary" @click="save('form')">确认</el-button>
    </div>
  </el-dialog>
</template>
<script>
import CustomPagerSelect from './select'
import { adminSaveConsult } from '@/api/consult'
export default {
  name: 'ConsultSetting',
  components: { CustomPagerSelect },
  data() {
    return {
      dialogFormVisible: false,
      title: '设置关联问题',
      loading: false,
      form: {}
    }
  },
  methods: {
    openEntity(data) {
      if (undefined !== data) {
        this.form = Object.assign({}, data)
        this.dialogFormVisible = true
      } else {
        this.dialogFormVisible = false
        this.$message.warning('请选择设置项')
      }
    },
    close() {
      Object.assign(this.$data.form, this.$options.data.call(this).form)
      this.dialogFormVisible = false
      this.$emit('fetch-data')
    },
    save(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.loading = true
          adminSaveConsult(this.form).then(res => {
            this.$message.success('保存成功！')
            this.loading = false
            this.close()
          }).catch(() => {
            this.loading = false
            this.$message.error('保存失败！')
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
